﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using OkTool.Regex;
namespace OkTool.Util
{
    public class RegexUtil: RegexPool
    {
        /// <summary>
        /// 通过正则表达式验证
        /// </summary>
        /// <param name="input">值</param>
        /// <param name="pattern">正则</param>
        /// <returns></returns>
        public static bool IsMatch(string input, string pattern)
        {

            Match match = System.Text.RegularExpressions.Regex.Match(input, pattern); // 使用正则表达式匹配输入

            return match != null && match.Success;
        }

        /// <summary>
        /// 获得匹配值,失败返回null
        /// </summary>
        /// <param name="input">字符串</param>
        /// <param name="pattern">正则表达式</param>
        /// <returns></returns>
        public static string MatchValue(string input, string pattern)
        {

            Match match = System.Text.RegularExpressions.Regex.Match(input, pattern); // 使用正则表达式匹配输入

            if (match.Success) // 如果匹配成功
            {
                return (match.Value); // 输出匹配的值
            }
            return null;
        }

        /// <summary>
        /// 匹配
        /// </summary>
        /// <param name="input"></param>
        /// <param name="pattern"></param>
        /// <returns></returns>
        public static Match Match(string input, string pattern)
        {

            Match match = System.Text.RegularExpressions.Regex.Match(input, pattern); // 使用正则表达式匹配输入
            return match;
            
        }
    }
}
